package com.multitrack.googlemap;

//import android.app.ActivityManager;

import java.util.ArrayList;
import java.util.Iterator;

import kr.ac.hansung.www.GPSManager;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class GMapDrawLine extends Overlay {
	private ArrayList<GeoPoint> polyline; // Contains set of points to be
											// connected.
	private Paint pathPaint = null;

	public GMapDrawLine(ArrayList<GeoPoint> arrayGeoPoint) {
		super();

		this.polyline = arrayGeoPoint;
		this.pathPaint = new Paint();
		this.pathPaint.setAntiAlias(true);
	}

	@Override
	public void draw(Canvas canvas, MapView mView, boolean shadow) {
		super.draw(canvas, mView, shadow);

		Projection projection = mView.getProjection();

		// Reset our paint.
		setPathPaint();

		Path routePath = new Path();

		// Add each point to the routePath.
		Iterator<GeoPoint> it = polyline.iterator();

		Point first = null;
		first = projection.toPixels(it.next(), first);
		routePath.moveTo(first.x, first.y);

		while (it.hasNext()) {
			Point outPoint = null;

			outPoint = projection.toPixels(it.next(), outPoint);

			routePath.lineTo(outPoint.x, outPoint.y);
			routePath.moveTo(outPoint.x, outPoint.y);

		}

		canvas.drawPath(routePath, pathPaint);
	}

	public void setPathPaint() {

		this.pathPaint.setStrokeWidth(4);
		this.pathPaint.setARGB(100, 113, 105, 252);
		this.pathPaint.setStyle(Paint.Style.STROKE);
	}
}
